//
//  UIDevice+Resolutions.m
//  MengLiao
//
//  Created by xiuxin on 2022/7/15.
//  Copyright © 2022 HZMengLiao. All rights reserved.
//
#import "UIDevice+Resolutions.h"



@implementation UIDevice (Resolutions)
- (UIDeviceResolution)resolution
{
    UIDeviceResolution resolution = UIDeviceResolution_Unknown;
    UIScreen *mainScreen = [UIScreen mainScreen];
    CGFloat scale = ([mainScreen respondsToSelector:@selector(scale)] ? mainScreen.scale : 1.0f);
    CGFloat pixelHeight = (CGRectGetHeight(mainScreen.bounds) * scale);
    CGFloat pixelWidth = (CGRectGetWidth(mainScreen.bounds) * scale);
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
        if (scale == 3.0f) {
            if (pixelHeight == 2436.0f && pixelWidth == 1125.0f)
                resolution = UIDeviceResolution_iPhoneRetina58;
            if (pixelHeight == 1125.0f && pixelWidth == 2436.0f)
                resolution = UIDeviceResolution_iPhoneRetina58;
            if (pixelHeight == 2208.0f && pixelWidth == 1242.0f)
                resolution = UIDeviceResolution_iPhoneRetina55;
            if (pixelHeight == 1242.0f && pixelWidth == 2208.0f)
                resolution = UIDeviceResolution_iPhoneRetina55;
            if (pixelHeight == 2688.0f && pixelWidth == 1242.0f)
                resolution = UIDeviceResolution_iPhoneRetina65;
            if (pixelHeight == 1242.0f && pixelWidth == 2688.0f)
                resolution = UIDeviceResolution_iPhoneRetina65;
            
        }else if (scale == 2.0f) {
            if ( (pixelHeight == 960.0f && pixelWidth == 640.0f) || (pixelHeight == 640.0f && pixelWidth == 960.0f))
                resolution = UIDeviceResolution_iPhoneRetina35;
            else if ( (pixelHeight == 1136.0f && pixelWidth == 640.0f) || (pixelHeight == 640.0f && pixelWidth ==1136.0f))
                resolution = UIDeviceResolution_iPhoneRetina4;
            else if ( (pixelHeight == 1334.0f && pixelWidth == 750.0f) || (pixelHeight == 750.0f && pixelWidth == 1334.0f))
                resolution = UIDeviceResolution_iPhoneRetina47;
            else if ( (pixelHeight == 1792.0f && pixelWidth == 828.0f) || (pixelHeight == 828.0f && pixelWidth == 1792.0f))
                resolution = UIDeviceResolution_iPhoneRetina61;
            
        } else if (scale == 1.0f && pixelHeight == 480.0f)
            resolution = UIDeviceResolution_iPhoneStandard;
        
    } else {
        if (scale == 2.0f && pixelHeight == 2048.0f) {
            resolution = UIDeviceResolution_iPadRetina;
            
        } else if (scale == 1.0f && pixelHeight == 1024.0f) {
            resolution = UIDeviceResolution_iPadStandard;
        }
    }
    
    return resolution;
}
+ (BOOL)is_XDevice{
    if ([[UIApplication sharedApplication] statusBarFrame].size.height > 20) {
        return YES;
    }
    return NO;
}
+ (BOOL)is_PlusDevice{
    if ([[UIDevice currentDevice] resolution] == UIDeviceResolution_iPhoneRetina55) {
        return YES;
    }else if ([[UIDevice currentDevice] resolution] == UIDeviceResolution_iPhoneRetina61){
        return YES;
    }else if ([[UIDevice currentDevice] resolution] == UIDeviceResolution_iPhoneRetina65){
        return YES;
    }
    return NO;
}


+ (BOOL)device_phoneX
{
    return [self is_XDevice];
}
+ (BOOL)device_phonePlus
{
    return [self is_PlusDevice];
}
@end

@implementation LMAppConfigure


+(CGFloat) GetLengthAdaptRate
{
    CGFloat rate = 1;
    if([[UIDevice currentDevice] resolution] == UIDeviceResolution_iPhoneRetina4 ||
       [[UIDevice currentDevice] resolution] == UIDeviceResolution_iPhoneRetina35)
    {
        rate = 320/375.0;
    }
    if([[UIDevice currentDevice] resolution] == UIDeviceResolution_iPhoneRetina47)
    {
        rate = 1.0;
    }
    else if([[UIDevice currentDevice] resolution] == UIDeviceResolution_iPhoneRetina55)
    {
        rate = 414/375.0;
    }
    else if([[UIDevice currentDevice] resolution] == UIDeviceResolution_iPhoneRetina58)
    {
        rate = 1.0;
    }
    else if([[UIDevice currentDevice] resolution] == UIDeviceResolution_iPhoneRetina61)
    {
         rate = 414/375.0;
    }
    else if([[UIDevice currentDevice] resolution] == UIDeviceResolution_iPhoneRetina65)
    {
        rate = 414/375.0;
    }
    else if([[UIDevice currentDevice] resolution] == UIDeviceResolution_iPadRetina)
    {
         rate = 414/375.0;
    }
    else if([[UIDevice currentDevice] resolution] == UIDeviceResolution_iPadStandard)
    {
        return 768.0/320.0;
    }
    return rate;
}



@end

